package cnblogs.guzb.multiredis;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 顾志兵
 * @mail ipiger@163.com
 * @since 2024-03-22
 */
@Component
@SpringBootApplication
public class MultiRedisAppMain {

    @Resource(name = "redis-template-db-0")
    RedisTemplate redisTemplate0;

    @Resource(name = "redis-template-db-1")
    RedisTemplate redisTemplate1;

    public static void main(String[] args) {
        SpringApplication.run(MultiRedisAppMain.class, args);
    }

    @EventListener(ApplicationReadyEvent.class)
    public void operateBook() {
        redisTemplate0.opsForValue().set("bookName", "三体");
        redisTemplate0.opsForValue().set("bookPrice", "102");

        redisTemplate1.opsForValue().set("bookName", "老人与海");
        redisTemplate1.opsForValue().set("bookPrice", "95");
    }
}
